#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    /**
     * @brief 生成杨辉三角的前 numRows 行
     * @param numRows 
     * @return vector<vector<int>> 
     */
    vector<vector<int>> generate(int numRows) {
        vector<vector<int>> ret(numRows);
        for (int i=0; i<numRows; ++i) {
            ret[i].resize(i+1);
            ret[i][0] = ret[i][i] = 1;
            for (int j=1; j<i; ++j) {
                ret[i][j] = ret[i-1][j-1] + ret[i-1][j];
            }
        }
        return ret;
    }

    /**
     * @brief 获取杨辉三角的第 rowIndex 行 [LC119]
     * @param rowIndex 
     * @return vector<int> 
     */
    vector<int> getRow(int rowIndex) {  // O(rowIndex) space
        vector<vector<int>> ret(2);
        int i;
        for (i=0; i<=rowIndex; ++i) {
            int i_curr = i%2;
            int i_other = (i+1)%2;
            ret[i_curr].resize(i+1);
            ret[i_curr][0] = ret[i_curr][i] = 1;
            for (int j=1; j<i; ++j) {
                ret[i_curr][j] = ret[i_other][j-1] + ret[i_other][j];
            }
        }
        return ret[rowIndex%2];
    }
};


int main(void) {
    Solution soln = Solution();
    soln.getRow(2);
    return 0;
}
